package hibernate.jaiku.utils;

import hibernate.jaiku.modelo.Comentario;
import hibernate.jaiku.modelo.Entrada;
import hibernate.jaiku.modelo.Usuario;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;


public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
             sessionFactory = new Configuration()
			.addClass(Usuario.class)
			.addClass(Entrada.class)
			.addClass(Comentario.class)
			.setProperty(Environment.HBM2DDL_AUTO, "create")
			.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLMyISAMDialect")
			.setProperty("hibernate.show_sql","true")
			.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/jaiku")
			.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver")
			.setProperty("hibernate.connection.username", "root")
			.setProperty("hibernate.connection.password", "root")
			.buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    
}
